<template>
	<view class="page-box">
		<view class="tab-box">
			<view class="tab-item" v-for="(item,index) in tabList" :key="index" @click="tabClick(index)">
				{{item.label}}
			</view>
			<view class="tab-line" :style="[tabLineStyle]"></view>
		</view>
		<view class="page-con">
			<province v-if="[0,1].includes(tabIndex)" :tabIndex="tabIndex" ></province>
			<index v-if="isIndex" ></index>
			<!-- <trajectory-tracking v-if="isTracking" :dataList='dataList' @fnShow='fnShow'></trajectory-tracking> -->
		</view>
	</view>
</template>

<script>
	import province from "./province.vue"
	import trajectoryTracking from "./trajectoryTracking.vue"
	import index from "./index.vue"
	export default {
		components: {
			province,
			trajectoryTracking,
			index
		},
		data() {
			return {
				tabIndex: 0,
				tabList: [{
					label: '本省车辆',
					component: "province",
				}, {
					label: '外省车辆',
					component: "province",
				}, {
					label: '轨迹查询',
					component: "province",
				}],
				// isTracking: false,
				isIndex: false,
				// dataList: {}
			}
		},
		computed: {
			// 计算tabline的位置和宽度
			tabLineStyle() {
				let width = 100 / this.tabList.length;
				return {
					width: width + '%',
					left: width * this.tabIndex + '%',
				}
			}
		},
		methods: {
			// tab切换
			tabClick(index) {
				this.tabIndex = index
				if (index == 2) {
					this.isIndex = true
				} else {
					this.isIndex = false
					this.isTracking = false
				}
			},
			// // 点击查询
			// eventClick(data) {
			// 	this.dataList = data
			// 	if (data) {
			// 		this.isIndex = false
			// 		this.isTracking = true
			// 	}
			// },
			// 点击信息查询
			// fnShow(item) {
			// 	this.isIndex = true
			// 	this.isTracking = false
			// },
		}
	}
</script>

<style lang="scss" scoped>
	.page-box {
		height: 94.5vh;
		display: flex;
		flex-direction: column;

		.tab-box {
			display: flex;
			position: relative;
			z-index: 9999;

			.tab-item {
				flex: 1;
				font-size: 32rpx;
				line-height: 2.6em;
				text-align: center;

				&.cur {
					color: #5881dc;
				}
			}

			.tab-line {
				position: absolute;
				bottom: 0;
				height: 2px;
				background: #5881dc;
				transition: left 0.4s;
			}
		}

		.page-con {
			flex: 1;
			position: relative;
		}
	}
</style>
